package com.ruoyi.repair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.repair.domain.PropertyInspectionPlan;
import com.ruoyi.repair.service.IPropertyInspectionPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检计划Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/repair/planIns")
public class PropertyInspectionPlanController extends BaseController
{
    @Autowired
    private IPropertyInspectionPlanService propertyInspectionPlanService;

    /**
     * 查询巡检计划列表
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyInspectionPlan propertyInspectionPlan)
    {
        startPage();
        List<PropertyInspectionPlan> list = propertyInspectionPlanService.selectPropertyInspectionPlanList(propertyInspectionPlan);
        return getDataTable(list);
    }

    /**
     * 导出巡检计划列表
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:export')")
    @Log(title = "巡检计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyInspectionPlan propertyInspectionPlan)
    {
        List<PropertyInspectionPlan> list = propertyInspectionPlanService.selectPropertyInspectionPlanList(propertyInspectionPlan);
        ExcelUtil<PropertyInspectionPlan> util = new ExcelUtil<PropertyInspectionPlan>(PropertyInspectionPlan.class);
        util.exportExcel(response, list, "巡检计划数据");
    }

    /**
     * 获取巡检计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(propertyInspectionPlanService.selectPropertyInspectionPlanByPlanId(planId));
    }

    /**
     * 新增巡检计划
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:add')")
    @Log(title = "巡检计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyInspectionPlan propertyInspectionPlan)
    {
        return toAjax(propertyInspectionPlanService.insertPropertyInspectionPlan(propertyInspectionPlan));
    }

    /**
     * 修改巡检计划
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:edit')")
    @Log(title = "巡检计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyInspectionPlan propertyInspectionPlan)
    {
        return toAjax(propertyInspectionPlanService.updatePropertyInspectionPlan(propertyInspectionPlan));
    }

    /**
     * 删除巡检计划
     */
    @PreAuthorize("@ss.hasPermi('repair:planIns:remove')")
    @Log(title = "巡检计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(propertyInspectionPlanService.deletePropertyInspectionPlanByPlanIds(planIds));
    }
}
